package model02;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class FileWriterEx {
	private String fileName;
	private String path;
	private String str;
	
	//constructor
	public FileWriterEx() {
		setPath(path);
		setStr(str);
	}
	
	//nhap
	public void nhapThongTin() {
		Scanner s = new Scanner(System.in);
		System.out.print("Noi luu: ");
		path = s.nextLine();
		
		System.out.print("Noi dung: ");
		str = s.nextLine();
	}
	
	//ghi noi dung ra file
	public void ghiNoiDung() {
		char buffer[] = new char[str.length()];
		str.getChars(0, str.length(), buffer, 0);
		try {
			FileWriter fw = new FileWriter(path);
			
			for(int i = 0; i < str.length(); i++) {
				fw.write(buffer[i]);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public String getStr() {
		return str;
	}
	public void setStr(String str) {
		this.str = str;
	}

}
